
const Pool = require("../../mysql/index");

class OrderDao {
  async getByUId(uid) {
    let sql = `SELECT * FROM \`order\` WHERE uId = ${uid}`
    console.log(sql)
    return await Pool.query(sql)
  }
  async insertOrder(uId, bookId, consignee, addr, phone, count) {
    const pad = function (num) {
      return ('00' + num).slice(-2)
    };
    let date = new Date(Date.now());
    date = date.getUTCFullYear()         + '-' +
        pad(date.getUTCMonth() + 1)  + '-' +
        pad(date.getUTCDate())
    let sql = `
      INSERT INTO \`order\` (uId ,bookId, createTime , consignee , deliveryAddress, phoneNumber , count) VALUES (${uId} , ${bookId}, '${date}' , '${consignee}' , '${addr}' , '${phone}' , ${count})
    `
    console.log(sql)
    return await Pool.query(sql)
  }

}

module.exports = new OrderDao();